<template>
  <div >
    <x-header :left-options="{showBack: true}" >课程详情</x-header>
    <group>
      <cell title="课程名称" :value="name"></cell>
      <cell-form-preview :list="courseList"></cell-form-preview>
    </group>
    <br>
    <x-button type="warn" text="取消课程" @click.native="showConfirm"></x-button>
    <confirm v-model="show" >
        
    </confirm>
  </div>
</template>
<script>
  import {XHeader, Actionsheet,Group ,Cell,CellFormPreview,XButton ,Confirm } from 'vux';
  import config from '../config.js';


  export default {
    
    data () {
      return {
        show:false,
      	name:1,
        courseList:[
          {label:"",value:"2016-2017"},
          {label:"课程老师",value:"罗老师"},
         
        ]
      }
     },
     mounted() {
      	let item=this.$route.query.item
        this.name=item.name;
        this.courseList=[
            {label:"上课地址",value:item.address},
            {label:"课程描述",value:item.description},
            {label:"课程负责人",value:item.dutyName},
            {label:"课程老师",value:item.teacherName},
            {label:"课程开始时间",value:item.startTime ? config.changeDate(item.startTime.time) : '未确定'},
            {label:"课程结束时间",value:item.endTime ? config.changeDate(item.endTime.time) : '未确定'},
            ]

      },
     methods:{
     	showConfirm(){
        this.$vux.confirm.show({
          title: '提示',
          content: '确认取消课程吗？',
          onConfirm :()=>{
            const courseId = this.$route.query.item.id;
            const studentId = localStorage.userid;
            this.$http({
              url:config.base+"apply/close",
              method:"POST",
              headers:{
                'content-type':'application/x-www-form-urlencoded; charset=UTF-8',
              },
              data:config.postBody({ courseId , studentId })
            }).then( rep => {
              if (rep.data.status === 200 ){
                this.$vux.toast.show({
                  text:"取消成功",
                  time:1000,
                  onHide:()=>{
                    this.$router.go(-1)
                  }
                })
              }else {
                this.$vux.toast.show({
                  text:rep.data.message,
                  time:1000
                })
              }
            }).catch( (error) => {
              this.$vux.loading.hide()
              this.$vux.toast.show({
                text:"网络错误",
                type:'warn'
              })
            });
          }
        })
      },
     },
     components: {
      XHeader,
      Actionsheet,
      Group,
      Cell,
      CellFormPreview,
      XButton,
      Confirm
    },
  }
</script>
<style>
</style>